﻿Public Class MessageService

#Region "Constants"
    Private Const MessagingUrl As System.String = "http://api.nabaztag.com/vl/FR/api.jsp"
#End Region

#Region "Shared Methods"
    Public Shared Function SendMessage(ByVal message As Messages.IRequest) As Response
        Dim queryString As System.String = message.GetQueryString
        If queryString.StartsWith("?") Then
            queryString.Remove(0, 1)
        End If

        Dim messageResponse As Response = SendMessage(queryString)
        Return messageResponse
    End Function

    Public Shared Function SendMessage(ByVal queryString As String) As Response
        If queryString.StartsWith("?") Then
            queryString.Remove(0, 1)
        End If
        Dim url As System.String = String.Format("{0}?{1}", MessagingUrl, queryString)

        Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(url)
        Dim response As System.Net.HttpWebResponse = request.GetResponse()

        Dim reader As New System.IO.StreamReader(response.GetResponseStream)
        Dim messageResponseText As System.String = reader.ReadToEnd

        reader.Close()

        Dim messageResponse As New Response(url, messageResponseText)
        Return messageResponse
    End Function
#End Region

End Class
